package com.txt;

import cn.dev33.satoken.SaManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.MessageFormat;

@SpringBootApplication
public class TxtAdminApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext context = SpringApplication.run(TxtAdminApplication.class, args);

        System.out.println("启动成功，Sa-Token 配置如下：" + SaManager.getConfig().toString());
        System.out.println("TXT启动成功...");
        // 从应用上下文对象中获取 Environment 对象
        Environment environment = context.getEnvironment();

        try {
            // 获取当前主机的 IP 地址
            String host = InetAddress.getLocalHost().getHostAddress();
            // 从 Environment 中获取应用启动的端口号，如果未配置则默认使用 8080
            String port = environment.getProperty("server.port", "8080");
            System.out.println(MessageFormat.format("应用启动在: http://{0}:{1}", host, port));
            System.out.println(MessageFormat.format("API接口访问地址：http://{0}:{1}/doc.html", host, port));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
